﻿using ConfExpert.Utility;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid;
using Extensions;
using System;
using System.Data;
using System.Drawing;

namespace ConfOrder.Shirt
{
    public partial class Accessory : XForm
    {
        public Accessory()
        {
            InitializeComponent();
        }

        private void Accessory_Load(object sender, EventArgs e)
        {
            this.MainToolbar.Visible = true;

            gvAksesuarStok.CalcRowHeight += gvAksesuarStok_CalcRowHeight;
            gvAksesuarStok.RowCellStyle += gvAksesuarAyrim_RowCellStyle;
            gvAksesuarAyrim.RowCellStyle += gvAksesuarAyrim_RowCellStyle;
            //gvAksesuarStok.RowStyle += gvAksesuarStok_RowStyle;

            cmbGroup.EditValueChanged += cmbGroup_EditValueChanged;
            cmbGroup.EditValue = "-";
        }

        void gvAksesuarStok_CalcRowHeight(object sender, RowHeightEventArgs e)
        {
            if (e.RowHandle > -1)
                if (e.RowHeight < notready.Height)
                    e.RowHeight = notready.Height;
        }

        void cmbGroup_EditValueChanged(object sender, EventArgs e)
        {
            switch (cmbGroup.EditValue.ToStringNN())
            {
                case "Brand":
                    gvAksesuarStok.Init("COGetAksesuarStok", AppSession.UserInfo.CustomerId, "Brand");
                    gvAksesuarStok.AddDetailGrid(gvAksesuarAyrim, "CustomerId,BrandId");
                    gvAksesuarAyrim.MakeColumnInvisible("CustomerId");
                    gvAksesuarAyrim.SetCaptions("Boy:Size", "Renk:Color", "Aciklama:Expl", "Etiket:Label", "SeriId:Series Id", "SezonId:Season Id");
                    splitContainerControl1.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Both;
                    splitContainerControl1.SplitterPosition = 340;
                    break;

                case "AksesuarId":
                    gvAksesuarStok.Init("COGetAksesuarStok", AppSession.UserInfo.CustomerId, "AksesuarId");
                    gvAksesuarStok.AddDetailGrid(gvAksesuarAyrim, "AksesuarId,CustomerId");
                    gvAksesuarAyrim.MakeColumnInvisible("AksesuarId", "CustomerId", "Boy", "Renk", "Aciklama", "Etiket", "SeriId", "ScA", "ProductCategoryId", "AksSeriId");
                    gvAksesuarStok.SetCaptions("Boy:Size", "Renk:Color", "Aciklama:Expl", "Etiket:Label", "AksSeriId:Series Id");
                    gvAksesuarAyrim.SetCaptions("SezonId:Season Id");
                    splitContainerControl1.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Both;
                    splitContainerControl1.SplitterPosition = 850;
                    break;

                default:
                    splitContainerControl1.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Panel1;
                    gvAksesuarStok.Init("COGetAksesuarStok", AppSession.UserInfo.CustomerId, "Aksesuar");
                    gvAksesuarStok.SetCaptions("Boy:Size", "Renk:Color", "Aciklama:Expl", "Etiket:Label", "AksSeriId:Series Id");
                    break;
            }

            gvAksesuarStok.Columns["CustomerId"].ColumnEdit = RepositoryManager.riCustomer;
            gvAksesuarStok.FormatAsNumber(0, "Qty", "TotalQty");
            gvAksesuarStok.AddSummary("Qty", "TotalQty");

            gvAksesuarAyrim.FormatAsNumber(0, "Qty");
            gvAksesuarAyrim.AddSummary("Qty");

            gvAksesuarStok.MakeReadOnly();
            gvAksesuarAyrim.MakeReadOnly();

            gvAksesuarStok.BestFitColumns();
            gvAksesuarAyrim.BestFitColumns();
        }


        void gvAksesuarStok_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            if (((GridView)sender).GetRowCellValue(e.RowHandle, "QtySelected").ToDecimalNN() > 0)
                e.Appearance.BackColor = Color.LightBlue;
            else
                e.Appearance.Combine((e.RowHandle & 1) != 0 ? gvAksesuarStok.Appearance.EvenRow : gvAksesuarStok.Appearance.OddRow);
        }

        void gvAksesuarAyrim_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                //string HoldFor = gvAksesuarAyrim.GetRowCellValue(e.RowHandle, "HoldFor").ToString();
                switch (e.Column.FieldName)
                {
                    case "Qty":
                    case "TotalQty":
                        e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                        //if (HoldFor != "")
                        //    e.Appearance.ForeColor = Color.Red;
                        return;
                }
            }
        }


    }
}
